<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                 label-width="68px">
            <el-form-item label="名称" prop="name">
                <el-input v-model="queryParams.name" placeholder="请输入名称" clearable
                          @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item label="排站规则" prop="allotPlaceRule">
                <el-select v-model="queryParams.allotPlaceRule" placeholder="请选择排站规则" clearable>
                    <el-option v-for="dict in dict.type.score_ex_model_allot_place_rule_dict" :key="dict.value"
                               :value="dict.value" :label="dict.label"/>
                </el-select>
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
                    <el-option v-for="dict in dict.type.score_ex_exam_status_dict" :key="dict.value" :label="dict.label"
                               :value="dict.value"/>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-popconfirm v-hasPermi="['score:score_ex_exam:add']" confirm-button-text='使用'
                               cancel-button-text='我自行创建'
                               icon="el-icon-question" title="是否使用考试模板创建" @confirm="usModelAdd"
                               @cancel="handleAdd">
                    <el-button slot="reference" type="primary" plain icon="el-icon-plus" size="mini">新增</el-button>
                </el-popconfirm>
            </el-col>
<!--            <el-col :span="1.5">-->
<!--                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"-->
<!--                           @click="handleDelete" v-hasPermi="['score:score_ex_exam:remove']">删除-->
<!--                </el-button>-->
<!--            </el-col>-->
            <div style="float: right;width: 20%;">
                <span style="color: red;font-size: 11px;font-weight: bold;top: 10px"> * 超过最后可修改时间的考试无法进行修改，请合理安排时间</span>
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"/>
            </div>
        </el-row>

        <el-table v-loading="loading" :data="score_ex_examList" @selection-change="handleSelectionChange" :height="table_height">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="名称" align="center" prop="name"/>
            <el-table-column label="考试日期" align="center" width="176px">
                <template slot-scope="scope">
                    <el-tag size="small" effect="plain" v-if="scope.row.exStartDate === scope.row.exEndDate">{{ scope.row.exStartDate }}</el-tag>
                    <el-tag v-else size="small" effect="plain">{{ scope.row.exStartDate }} ~ {{ scope.row.exEndDate }}</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="最大学生数" align="center" prop="maxStudent"/>
            <el-table-column label="现场考官权重(%)" align="center" prop="sceneExaminerWi"/>
            <el-table-column label="中控考官权重(%)" align="center" prop="centerExaminerWi"/>
            <el-table-column label="远程考官权重(%)" align="center" prop="sshExaminerWi"/>
            <el-table-column label="考试间隔时间(分)" align="center" prop="examIntervalTime"/>
            <el-table-column label="考场数量" align="center" prop="scoreExExamPlaceCount"/>
            <el-table-column label="排站规则" align="center" prop="allotPlaceRule">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.score_ex_model_allot_place_rule_dict"
                              :value="scope.row.allotPlaceRule"/>
                </template>
            </el-table-column>
            <el-table-column label="必过技能" align="center" prop="mustSkill" :formatter="skillFormat"/>
            <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.score_ex_exam_status_dict" :value="scope.row.status"/>
                </template>
            </el-table-column>
            <el-table-column label="最后可修改时间" align="center" width="135">
                <template slot-scope="scope">
                    <el-tag type="danger" size="small" effect="plain">{{ scope.row.lastTime }}</el-tag>
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                               v-hasPermi="['score:score_ex_exam:edit']">修改
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" :disabled="scope.row.status!=1" v-hasPermi="['score:score_ex_exam:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                    @pagination="getList"/>

        <el-drawer title="选择考试模版" :visible.sync="ex_model.open" size="70%" append-to-body
                   :destroy-on-close="true">
            <SELECT_MODEL @handleCheckModel="handleCheckModel"/>
        </el-drawer>

        <!-- 添加或修改考试对话框 -->
        <el-drawer :title="title" :visible.sync="open" size="70%" append-to-body :destroy-on-close="true"
                   :before-close="drawerClose">
                <el-tabs v-model="form_tab_action" type="card">
                    <el-tab-pane name="data">
                        <span slot="label"><i class="el-icon-tickets"/> 参数设置</span>
                        <el-form ref="form" :model="form" :rules="rules" label-width="130px" size="mini">
                            <el-row :gutter="11" style="margin-left: 20px">
                                <el-col :span="6" style="margin-top: 50px">
                                    <el-form-item label="名称" prop="name">
                                        <el-input v-model="form.name" placeholder="请输入名称" style="width: 160px;"
                                                  :disabled="isAllot" clearable/>
                                    </el-form-item>
                                    <el-form-item label="最大学生数" prop="maxStudent">
                                        <el-input-number :min="1" v-model="form.maxStudent"
                                                         placeholder="请输入最大学生数" :disabled="isAllot"
                                                         style="width: 160px;"/>
                                    </el-form-item>
                                    <el-form-item label="排站规则" prop="allotPlaceRule">
                                        <el-select v-model="form.allotPlaceRule" placeholder="请选择排站规则"
                                                   style="width: 160px;" :disabled="isAllot" clearable>
                                            <el-option v-for="dict in dict.type.score_ex_model_allot_place_rule_dict"
                                                       :key="dict.value" :value="dict.value" :label="dict.label"/>
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="考试间隔时间(分)" prop="examIntervalTime">
                                        <el-input-number :min="1" v-model="form.examIntervalTime" :disabled="isAllot"
                                                         placeholder="请输入考试间隔时间(分)" style="width: 160px;"/>
                                    </el-form-item>
                                    <el-form-item label="是否展示姓名" prop="nameShow">
                                        <el-radio-group v-model="form.nameShow">
                                            <el-radio label="1">展示</el-radio>
                                            <el-radio label="2">不展示</el-radio>
                                        </el-radio-group>
                                    </el-form-item>
                                    <el-form-item label="考试日期" prop="exDate">
                                        <el-date-picker v-model="form.exDate" type="daterange" value-format="yyyy-MM-dd"
                                                        :picker-options="pickerOptions" :disabled="isAllot"
                                                        @input="$forceUpdate()"
                                                        range-separator="~" start-placeholder="开始日期"
                                                        end-placeholder="结束日期" style="width: 470px;"/>
                                    </el-form-item>
                                    <el-form-item label="必过技能" prop="mustSkill">
                                        <el-select v-model="form.mustSkill" placeholder="请选择必过技能(多选,可自定义)"
                                                   clearable :disabled="isAllot"
                                                   multiple filterable allow-create default-first-option
                                                   style="width: 470px">
                                            <el-option v-for="dict in dict.type.score_ex_model_must_skill_dict"
                                                       :key="dict.label"
                                                       :label="dict.label" :value="dict.label"/>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="6" style="margin-top: 50px">
                                    <el-form-item label="最后可修改时间" prop="lastTime">
                                        <el-tag type="danger" size="medium" effect="plain">{{ form.lastTime }}</el-tag>
                                    </el-form-item>
                                    <el-form-item label="现场考官权重(%)" prop="sceneExaminerWi">
                                        <el-input-number :min="0" v-model="form.sceneExaminerWi"
                                                         placeholder="请输入现场考官权重(%)" :disabled="isAllot"
                                                         style="width: 160px;"/>
                                    </el-form-item>
                                    <el-form-item label="中控考官权重(%)" prop="centerExaminerWi">
                                        <el-input-number :min="0" v-model="form.centerExaminerWi" :disabled="isAllot"
                                                         placeholder="请输入现场考官权重(%)" style="width: 160px;"/>
                                    </el-form-item>
                                    <el-form-item label="远程考官权重(%)" prop="sshExaminerWi">
                                        <el-input-number :min="0" v-model="form.sshExaminerWi"
                                                         placeholder="请输入远程考官权重(%)" :disabled="isAllot"
                                                         style="width: 160px;"/>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="11">
                                    <div style="margin-bottom: 10px;float: right">
                                        <el-button type="success" @click="submitForm" :disabled="isDisabled(true)" plain round>保存参数</el-button>
                                        <el-button type="primary" @click="allotExam" :disabled="isDisabled(true)" plain round>排站</el-button>
                                        <el-button type="primary" @click="clearAllotExam" :disabled="isDisabled(false)" plain round>清除排站数据</el-button>
                                    </div>
                                    <el-table :data="scoreExExamTimeList" size="mini"
                                              ref="scoreExExamTime" height="300">
                                        <el-table-column align="center" label="考试时间分段">
                                            <template slot="header" slot-scope="scope">
                                                <span>考试时间分段</span>
                                                <el-button type="primary" icon="el-icon-plus" size="mini"
                                                           style="float: right" v-show="!isAllot"
                                                           @click="handleAddScoreExExamTime" plain>添加一行
                                                </el-button>
                                            </template>
                                            <el-table-column label="名称" prop="name" align="center" width="150">
                                                <template slot-scope="scope">
                                                    <el-input v-model="scope.row.name" size="mini"
                                                              placeholder="请输入名称" :disabled="isAllot"
                                                              clearable/>
                                                </template>
                                            </el-table-column>
                                            <el-table-column label="时间范围" align="center" prop="startTime">
                                                <template slot-scope="scope">
                                                    <el-time-picker is-range size="mini" v-model="scope.row.timeRange"
                                                                    range-separator="至" start-placeholder="开始时间"
                                                                    end-placeholder="结束时间"
                                                                    placeholder="选择时间范围"
                                                                    value-format="HH:mm:ss" :disabled="isAllot"/>
                                                </template>
                                            </el-table-column>
                                            <el-table-column width="45">
                                                <template slot="header" slot-scope="scope">
                                                    <i class="el-icon-delete"/>
                                                </template>
                                                <template slot-scope="scope">
                                                    <el-button type="text" icon="el-icon-circle-close"
                                                               style="margin: 0;padding: 0"
                                                               @click="handleDeleteScoreExExamTime(scope.$index)"/>
                                                </template>
                                            </el-table-column>
                                        </el-table-column>
                                    </el-table>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-divider><i class="el-icon-s-home"/>考场</el-divider>
                                <div>
                                    <el-button type="primary" icon="el-icon-plus"
                                               @click="handleAddScoreExExamPlace(null)" v-show="!isAllot"
                                               style="position:fixed;right: 100px" plain>添加考场
                                    </el-button>
                                    <div>
                                        <EX_EXAM_PLACE style="float: left" v-for="(place,index) in scoreExExamPlaceList"
                                                       :deptOptions="deptOptions" :disabled="isAllot"
                                                       :ex_placeList="ex_placeList" :index="index"
                                                       :length="scoreExExamPlaceList.length" :place="place"
                                                       @handleDeleteScoreExModelPlace="handleDeleteScoreExExamPlace"
                                                       @placePositionChange="placePositionChange"/>
                                    </div>
                                </div>
                            </el-row>
                        </el-form>
                    </el-tab-pane>
                    <el-tab-pane name="students">
                        <span slot="label"><i class="el-icon-user"/> 分配考生</span>
                        <STUDENTS :form="form" :deptOptions="deptOptions"/>
                    </el-tab-pane>
                    <el-tab-pane name="allot" :disabled="form.allotStatus!='2'">
                        <span slot="label"><i class="el-icon-box"/> 排站信息</span>
                        <ALLOT :form="form"/>
                    </el-tab-pane>
                </el-tabs>
        </el-drawer>
    </div>
</template>

<script>
import EX_EXAM_PLACE from "./place/index.vue";//单个考站页面
import SELECT_MODEL from "./select_model/index.vue";//选择模版页面
import ALLOT from "./form/allot.vue";//排站页面
import STUDENTS from "./student/index.vue";//学生页面
import {
    listScore_ex_exam,
    getScore_ex_exam,
    delScore_ex_exam,
    addScore_ex_exam,
    updateScore_ex_exam,
    allot_exam,
    clear_allot_exam
} from "@/api/score/score_ex_exam";
import {getEx_model} from "@/api/score/ex_model";
import {deptTreeSelect} from "@/api/system/user";
import {before, sleep, yesterday, beforeNow, afterNow} from "@/utils/zzDouUtils/dateUtil";
import {
    fillObj,
    isEmptyStr,
     isNotEmptyStr,
    isNotNull,
    isNull,
    parseObj,
    toJsonStr
} from "@/utils/zzDouUtils/objUtil";
import {isEmptyArr, isNotEmptyArr, swap} from "@/utils/zzDouUtils/arrayUtil";
import {listEx_place} from "@/api/basic/ex_place";
import {parseTime} from "@/utils/ruoyi";

var searchParam = {pageSize: 1000, pageNum: 1};
export default {
    name: "Score_ex_exam",
    dicts: ['score_ex_exam_status_dict', 'score_ex_model_allot_place_rule_dict', 'score_ex_model_must_skill_dict'],
    components: {EX_EXAM_PLACE, SELECT_MODEL, ALLOT, STUDENTS},
    data() {
        return {
            loading: true,// 遮罩层
            ids: [],// 选中数组
            single: true,// 非单个禁用
            multiple: true,// 非多个禁用
            showSearch: true,// 显示搜索条件
            total: 0,// 总条数
            score_ex_examList: [],// 考试表格数据
            scoreExExamTimeList: [],//考试时间分段数据
            scoreExExamPlaceList: [],//考试考场数据
            ex_modelList: [],//考试模版列表
            ex_placeList: [],//考站列表
            // 科室树选项
            deptOptions: null,
            title: "",// 弹出层标题
            open: false,// 是否显示弹出层
            queryParams: {// 查询参数
                pageNum: 1,
                pageSize: 10,
                name: null,
                exDate: null,
                mustSkill: null,
                status: null,
            },
            form: {},// 表单参数
            form_tab_action: 'data',
            isAllot: false,//是否分配
            rules: {// 表单校验
                name: [
                    {required: true, message: "请输入模版名称", trigger: "blur"}
                ],
                exDate: [
                    {type: 'array', required: true, message: "请选择考试日期", trigger: "blur"}
                ],
                maxStudent: [
                    {required: true, message: "请输入最大学生数", trigger: "blur"}
                ],
                sceneExaminerWi: [
                    {required: true, message: "请输入现场考官权重(%)", trigger: "blur"}
                ],
                centerExaminerWi: [
                    {required: true, message: "请输入中控考官权重(%)", trigger: "blur"}
                ],
                sshExaminerWi: [
                    {required: true, message: "请输入远程考官权重(%)", trigger: "blur"}
                ],
                examIntervalTime: [
                    {required: true, message: "请输入考试间隔时间(分)", trigger: "blur"}
                ],
                allotPlaceRule: [
                    {required: true, message: "请选择排站规则", trigger: "blur"},
                ],
                nameShow: [
                    {required: true, message: "请选择是否展示学员姓名", trigger: "blur"},
                ],
            },
            add_popover_visible: false,//添加按钮开关
            ex_model: {
                open: false,
                modelId: null,
            },
            pickerOptions: {//时间快捷选择
                disabledDate(time) {//禁用范围
                    return time.getTime() < yesterday();
                }
            },
        };
    },
    created() {
        this.getList();
    },
    methods: {
        afterNow,
        isNotEmptyStr,
        beforeNow,
        parseTime,
        /** 查询考站表列表 */
        getExPlaceList() {
            listEx_place(searchParam).then(response => {
                this.ex_placeList = response.rows;
            });
        },
        /** 查询科室下拉树结构 */
        getDeptTree() {
            deptTreeSelect().then(response => {
                this.deptOptions = response.data;
            });
        },
        /** 查询考试列表 */
        getList() {
            this.loading = true;
            listScore_ex_exam(this.queryParams).then(response => {
                this.score_ex_examList = response.rows;
                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                name: null,
                exDate: [],
                laseTime: null,
                maxStudent: null,
                sceneExaminerWi: null,
                centerExaminerWi: null,
                sshExaminerWi: null,
                examIntervalTime: null,
                allotPlaceRule: null,
                mustSkill: [],
                lastTime: null,
                status: null,
                nameShow: '2',
                allotStatus: 1,
            };
            this.isAllot = false;
            this.scoreExExamTimeList = [];
            this.scoreExExamPlaceList = [];
            this.getDeptTree();
            this.getExPlaceList();
            this.resetForm("form");
        },
        isDisabled(flag) {
            let b = afterNow(this.form.lastTime);
            return b ? b : (flag ? this.isAllot : !this.isAllot);
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.open = true;
            this.title = "添加考试";
            this.handleAddScoreExExamPlace();
            this.handleAddScoreExExamTime();
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            getScore_ex_exam(row.id).then(response => {
                this.parseForm(response.data);
                this.open = true;
                this.title = "修改考试";
            });
        },
        /** 格式化表单 */
        parseForm(data) {
            this.form = data;
            this.isAllot = data.allotStatus == '2';//true 已排站
            this.$set(this.form,'exDate',[parseTime(data.exStartDate, '{y}-{m}-{d}'), parseTime(data.exEndDate, '{y}-{m}-{d}')]);
            this.$set(this.form,'mustSkill',parseObj(data.mustSkill));
            this.scoreExExamTimeList = this.parseSearchRangeTime(data.exExamTimeList);
            this.scoreExExamPlaceList = data.exExamPlaceList;
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    //检查三个权重
                    if (this.checkExaminerWi()) return;
                    //检查时间分段
                    if (this.checkTimeListHasNull()) return;
                    //检查房间列表
                    if (this.checkPlaceListHasNull()) return;
                    this.form.exExamTimeList = this.parseAddRangeTime(this.scoreExExamTimeList);
                    this.form.exExamPlaceList = this.scoreExExamPlaceList;
                    this.form.exStartDate = this.form.exDate[0];
                    this.form.exEndDate = this.form.exDate[1];
                    this.form.mustSkill = toJsonStr(this.form.mustSkill);
                    if (this.form.id != null) {
                        updateScore_ex_exam(this.form).then(response => {
                            this.parseForm(response.data);
                            this.$modal.msgSuccess("修改成功");
                            this.getList();
                        });
                    } else {
                        addScore_ex_exam(this.form).then(response => {
                            this.parseForm(response.data);
                            this.$modal.msgSuccess("新增成功");
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 排站 */
        allotExam() {
            const loading = this.$loading({lock: true, text: '努力排站中…………'});
            allot_exam(this.form.id).then(response => {
                this.parseForm(response.data);
                this.$modal.msgSuccess("排站成功");
                loading.close();
            })
        },
        /** 清除排站 */
        clearAllotExam() {
            clear_allot_exam(this.form.id).then(response => {
                this.parseForm(response.data);
                this.$modal.msgSuccess("清除排站数据成功");
            })
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids;
            this.$modal.confirm('是否确认删除考试编号为"' + ids + '"的数据项？').then(function () {
                return delScore_ex_exam(ids);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => {
            });
        },
        //必过技能格式化
        skillFormat(row, column, cellValue) {
            const obj = parseObj(cellValue);
            let str = '';
            for (let i = 0; i < obj.length; i++) {
                str += obj[i];
                if (i != obj.length - 1) {
                    str += '、';
                }
            }
            return str;
        },
        /** ====================================== */
        usModelAdd() {//使用模板创建
            this.ex_model.open = true;
        },
        /** 选择模版 */
        async handleCheckModel(modelId) {
            const loading = this.$loading({lock: true, text: '正在整合模板：【基础数据】 （30%）'});
            this.reset();
            //查询模版详细信息
            const response = await getEx_model(modelId);
            const data = response.data;
            this.form = {//基础数据
                name: null,
                exDate: null,
                maxStudent: data.maxStudent,
                sceneExaminerWi: data.sceneExaminerWi,
                centerExaminerWi: data.centerExaminerWi,
                sshExaminerWi: data.sshExaminerWi,
                examIntervalTime: data.examIntervalTime,
                allotPlaceRule: data.allotPlaceRule,
                mustSkill: data.mustSkillList,
                status: null,
                allotStatus: 1,
                lastTime: null,
                nameShow: '2',
            };
            this.scoreExExamTimeList = this.parseSearchRangeTime(data.scoreExModelTimeList);
            data.scoreExModelPlaceList.forEach(place => {//场地
                this.handleAddScoreExExamPlace({deptId: place.deptId, skillId: place.skillId});
            })
            await sleep(800).then(() => {
                loading.setText("正在整合模板：【时间分段数据】 （70%）")
            })
            await sleep(800).then(() => {
                loading.setText('正在整合模板：【考场数据】 （90%）')
            })
            await sleep(800).then(() => {
                loading.setText('正在整合模板：【正在渲染】 （100%）')
            })
            await sleep(500).then(() => {
                this.ex_model.open = false;
                this.open = true;
                this.title = "添加考试";
                loading.close();
            })
        },
        /** 格式化最后修改时间 */
        parseLastTime(){
            if (isNotEmptyStr(this.form.exDate[0]) && isNotEmptyArr(this.scoreExExamTimeList)){
                let date = new Date(this.form.exDate[0] + ' ' + this.scoreExExamTimeList[0].timeRange[0]);
                date.setHours(date.getHours()-2);
                this.$set(this.form,'lastTime',parseTime(date,'{y}-{m}-{d} {h}:{i}'));
            }
        },
        /** 考试时间分段表添加按钮操作 */
        handleAddScoreExExamTime() {
            const now = "00:00:00";
            this.scoreExExamTimeList.push({name: '', timeRange: [now, now]});
        },
        /** 考试模版时间分段表删除按钮操作 */
        handleDeleteScoreExExamTime(index) {
            if (this.scoreExExamTimeList.length <= 1) {
                return;
            }
            this.$delete(this.scoreExExamTimeList, index)
        },
        /** 添加一行考场 */
        handleAddScoreExExamPlace(obj) {
            if (isNull(obj)) {
                obj = {deptId: null, skillId: null, placeId: null, sheetArr: [], num: 1, waitNum: 4};
            } else {
                obj = fillObj(obj, {placeId: null, sheetArr: []});
            }
            this.scoreExExamPlaceList.push(obj);
        },
        /** 删除一行 */
        handleDeleteScoreExExamPlace(index) {
            if (this.scoreExExamPlaceList.length <= 1) {
                return;
            }
            this.$delete(this.scoreExExamPlaceList, index);
        },
        //格式化时间范围
        parseAddRangeTime(timeArr) {
            let newArr = [];
            timeArr.forEach(item => {
                newArr.push({name: item.name, startTime: item.timeRange[0], endTime: item.timeRange[1]})
            })
            return newArr;
        },
        parseSearchRangeTime(timeArr) {
            let newArr = [];
            timeArr.forEach(item => {
                newArr.push({name: item.name, timeRange: [item.startTime, item.endTime]})
            })
            return newArr;
        },
        /** 场地位置变化  option=true前进  false后退*/
        placePositionChange(option, index) {
            this.scoreExExamPlaceList = swap(this.scoreExExamPlaceList, index, index + (option ? -1 : 1));
        },
        /** 关闭修改抽屉的回调 */
        drawerClose(done) {
            this.form_tab_action = 'data';
            done();
        },
        //----------------- 提交前的检查 ----------------------
        /** 检查三个权重 */
        checkExaminerWi() {
            const wi = parseInt(this.form.sceneExaminerWi) + parseInt(this.form.centerExaminerWi) + parseInt(this.form.sshExaminerWi);
            if (wi > 100 || wi < 90) {
                this.$modal.msgError('权重占比总和不可大于100或者小于90');
                return true;
            }
            return false;
        },
        /** 检查时间分段 */
        checkTimeListHasNull() {
            let msg = null;
            for (let i = 0; i < this.scoreExExamTimeList.length; i++) {
                const time = this.scoreExExamTimeList[i];
                if (isEmptyStr(time.name)) {
                    msg = `时间分段第${(i + 1)}行名称为空`;
                    break;
                }
                if (isEmptyArr(time.timeRange)) {
                    msg = `时间分段第${(i + 1)}行时间范围为空`;
                    break;
                }
                if (i !== 0 && before(time.timeRange[0], this.scoreExExamTimeList[i - 1].timeRange[1])) {//校验时间合法性
                    msg = `时间分段第${(i + 1)}行开始时间不能在第${(i)}行结束时间之前`;
                    break;
                }
            }
            if (isNotNull(msg)) {
                this.$modal.msgError(msg);
                return true;
            }
            return false;
        },
        /** 检查场地列表是否有空值 */
        checkPlaceListHasNull() {
            let msg = null;
            for (let i = 0; i < this.scoreExExamPlaceList.length; i++) {
                if (isNull(this.scoreExExamPlaceList[i].waitNum) || this.scoreExExamPlaceList[i].waitNum < 1) {
                    msg = `考场${(i + 1)}排队人数格式错误`;
                    break;
                }
                if (isNull(this.scoreExExamPlaceList[i].num) || this.scoreExExamPlaceList[i].num < 1) {
                    msg = `考场${(i + 1)}考场数量格式错误`;
                    break;
                }
                if (isEmptyStr(this.scoreExExamPlaceList[i].deptId)) {
                    msg = `考场${(i + 1)}科室未选择`;
                    break;
                }
                if (isEmptyStr(this.scoreExExamPlaceList[i].skillId)) {
                    msg = `考场${(i + 1)}技能未选择`;
                    break;
                }
                if (isEmptyStr(this.scoreExExamPlaceList[i].placeId)) {
                    msg = `考场${(i + 1)}考试场地未选择`;
                    break;
                }
            }
            if (isNotNull(msg)) {
                this.$modal.msgError(msg);
                return true;
            }
            return false;
        }
    },
    watch: {
        'form.exDate': {
            handler(newVal, oldVal) {
                this.parseLastTime();
            },
            deep: true
        },
        scoreExExamTimeList: {
            handler(newVal, oldVal) {
                this.parseLastTime();
            },
            deep: true
        }
    }
};
</script>
